VERSION 5.00
Object = "{4B319B44-7A19-47DD-B3ED-C6B589B398A7}#1.0#0"; "MoxCdBurn.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   5760
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7320
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5760
   ScaleWidth      =   7320
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdCreateIso 
      Caption         =   "&Create ISO image"
      Height          =   375
      Left            =   4920
      TabIndex        =   20
      Top             =   2040
      Width           =   2055
   End
   Begin VB.CheckBox chkDebug 
      Caption         =   "Debug mode"
      Height          =   255
      Left            =   4920
      TabIndex        =   19
      Top             =   3840
      Width           =   2055
   End
   Begin MSComDlg.CommonDialog dlgOpen 
      Left            =   6120
      Top             =   5160
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdErase 
      Caption         =   "E&rase disc"
      Height          =   375
      Left            =   4920
      TabIndex        =   17
      Top             =   3240
      Width           =   2055
   End
   Begin VB.CommandButton cmdWrite 
      Caption         =   "&Write ISO image"
      Height          =   375
      Left            =   4920
      TabIndex        =   16
      Top             =   2640
      Width           =   2055
   End
   Begin VB.CommandButton cmdLock 
      Caption         =   "&Lock"
      Height          =   375
      Left            =   4920
      TabIndex        =   15
      Top             =   840
      Width           =   2055
   End
   Begin VB.CommandButton cmdEject 
      Caption         =   "&Eject"
      Height          =   375
      Left            =   4920
      TabIndex        =   14
      Top             =   1440
      Width           =   2055
   End
   Begin VB.Frame Frame1 
      Caption         =   "Drive and disc properties"
      Height          =   4695
      Left            =   240
      TabIndex        =   2
      Top             =   720
      Width           =   4455
      Begin VB.CommandButton cmdRefresh 
         Caption         =   "&Refresh"
         Height          =   375
         Left            =   120
         TabIndex        =   10
         Top             =   4080
         Width           =   4215
      End
      Begin VB.Label lblFormat 
         Caption         =   "Disc format :"
         Height          =   255
         Left            =   120
         TabIndex        =   13
         Top             =   1080
         Width           =   2895
      End
      Begin VB.Label lblBUFE 
         Caption         =   "Buffer underun free :"
         Height          =   255
         Left            =   120
         TabIndex        =   12
         Top             =   3600
         Width           =   2895
      End
      Begin VB.Label lblCurWriteSpeed 
         Caption         =   "Current write speed :"
         Height          =   255
         Left            =   120
         TabIndex        =   11
         Top             =   2880
         Width           =   2895
      End
      Begin VB.Label lblBuffer 
         Caption         =   "Buffer size :"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   3240
         Width           =   2895
      End
      Begin VB.Label lblMaxReadSpeed 
         Caption         =   "Max read speed :"
         Height          =   255
         Left            =   120
         TabIndex        =   8
         Top             =   2520
         Width           =   2895
      End
      Begin VB.Label lblMaxWrSpeed 
         Caption         =   "Max write speed :"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   2160
         Width           =   3615
      End
      Begin VB.Label lblLoaded 
         Caption         =   "Media loaded :"
         Height          =   255
         Left            =   120
         TabIndex        =   6
         Top             =   720
         Width           =   2895
      End
      Begin VB.Label lblRecorder 
         Caption         =   "Cd recorder : "
         Height          =   255
         Left            =   120
         TabIndex        =   5
         Top             =   360
         Width           =   2895
      End
      Begin VB.Label lblType 
         Caption         =   "Disc type :"
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   1440
         Width           =   2895
      End
      Begin VB.Label lblStatus 
         Caption         =   "Disc status :"
         Height          =   255
         Left            =   120
         TabIndex        =   3
         Top             =   1800
         Width           =   4215
      End
   End
   Begin VB.ComboBox cmbDrive 
      Height          =   315
      Left            =   240
      TabIndex        =   1
      Top             =   240
      Width           =   4455
   End
   Begin VB.CommandButton cmdOpen 
      Caption         =   "&Open"
      Height          =   375
      Left            =   4800
      TabIndex        =   0
      Top             =   240
      Width           =   1095
   End
   Begin MoxCdBurnLibCtl.MxCtl mx 
      Left            =   5520
      OleObjectBlob   =   "frmMain.frx":0000
      Top             =   5160
   End
   Begin VB.Label lblEvents 
      Height          =   255
      Left            =   4920
      TabIndex        =   18
      Top             =   4320
      Width           =   2055
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'******************************************************************
'* File name     : frmMain.frm
'* Version       : 0.2.0
'* Last revision : 15/01/05
'* Purpose       : Main form that manages features showing
'*******************************************************************

'Copyright (C) 2004  Michele Moccia

'This program is free software; you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation; either version 2 of the License, or
'(at your option) any later version.
'
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'GNU General Public License for more details.
'
'You should have received a copy of the GNU General Public License
'along with this program; if not, write to the Free Software
'Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Option Explicit

Private bDriveOpened As Boolean
Private bRestore As Boolean

Private Sub chkDebug_Click()

    If chkDebug.Value = 1 Then
        mx.SetDebug True
    Else
        mx.SetDebug False
    End If

End Sub

Private Sub cmdCreateIso_Click()

    Dim frm As frmCreateIso
    
    Set frm = New frmCreateIso
    frm.MxControl = mx
    If bDriveOpened Then
        If mx.IsMediaLoaded And mx.IsDriveCapable(eDriveCap.WritesCDR) Then
            frm.bRecorder = True
        End If
    End If
    frm.Show 1, Me
    If frm.IsoFileName <> "" Then
        Call WriteIsoFileToCd(frm.IsoFileName)
    End If
    Set frm = Nothing

End Sub

Private Sub cmdEject_Click()

    mx.Eject

End Sub

Private Sub cmdErase_Click()

    Call CurrentStatus(False)
    bRestore = True
    EnableControls False
    cmdOpen.Enabled = False
    chkDebug.Enabled = False
    lblEvents.Caption = "Erasing disc..."
    mx.EraseDisc True

End Sub

Private Sub cmdLock_Click()

    If cmdLock.Caption = "&Lock" Then
        mx.LockDrive
        If mx.IsDriveLocked = True Then
            cmdLock.Caption = "&Unlock"
        End If
    Else
        mx.UnlockDrive
        If mx.IsDriveLocked = False Then
            cmdLock.Caption = "&Lock"
        End If
    End If

End Sub

Private Sub cmdOpen_Click()

    bDriveOpened = mx.OpenDrive(cmbDrive.ListIndex)
    
    Call EnableControls(True)
    Call SetProperties(True)

End Sub

Private Sub cmdRefresh_Click()

    Call SetProperties(True)

End Sub

Private Sub cmdWrite_Click()

    Dim frm As frmWrite

    dlgOpen.Filter = "iso image (*.iso)|*.iso"
    dlgOpen.DefaultExt = "iso"
    dlgOpen.ShowOpen
    
    If dlgOpen.FileName = "" Then Exit Sub
    Call WriteIsoFileToCd(dlgOpen.FileName)

End Sub

Private Sub WriteIsoFileToCd(ByVal sFileName As String)
    Dim frm As frmWrite
    
    Set frm = New frmWrite
    frm.FileName = sFileName
    frm.MxControl = mx
    
    frm.Show 1, Me
    Set frm = Nothing
    
End Sub

Private Sub Form_Load()

    Dim i As Integer
      
    Me.Caption = App.Title
    For i = 0 To mx.GetDriveCount - 1
        cmbDrive.AddItem DriveData(i)
    Next i

    cmbDrive.ListIndex = 0
    Call EnableControls(False)

End Sub

Private Function DriveData(iIndex As Integer) As String
                
    DriveData = mx.IndexToDriveLetter(iIndex) & " " & _
                Trim(mx.GetDriveVendor(iIndex)) & " " & _
                Trim(mx.GetDriveName(iIndex)) & " Version " & _
                Trim(mx.GetFirmware(iIndex))
                

End Function

Private Sub SetProperties(bFill As Boolean)

    Dim sRet As String

    lblRecorder.Caption = "Cd recorder :"
    lblStatus.Caption = "Disc status :"
    lblFormat.Caption = "Disc format :"
    lblType.Caption = "Disc type :"
    lblLoaded.Caption = "Media loaded :"
    lblBuffer.Caption = "Buffer size :"
    lblMaxWrSpeed.Caption = "Max write speed :"
    lblMaxReadSpeed.Caption = "Max read speed :"
    lblCurWriteSpeed.Caption = "Current write speed :"
    lblBUFE.Caption = "Buffer underun free :"
    
    If (bFill = False) Or (bDriveOpened = False) Then Exit Sub
    
    If mx.IsDriveCapable(WritesCDR) = True Then
        sRet = " yes"
    Else
        sRet = " no"
        cmdWrite.Enabled = False
        cmdErase.Enabled = False
    End If
    lblRecorder.Caption = lblRecorder.Caption & sRet
    
    If mx.IsMediaLoaded = True Then
        sRet = " yes"
    Else
        sRet = " no"
    End If
    lblLoaded.Caption = lblLoaded.Caption & sRet
  
    
    Select Case mx.GetDiscStatus
    Case dsComplete
        sRet = " complete"
    Case dsIncomplete
        sRet = " incomplete (still appendable)"
    Case dsEmpty
        sRet = " empty"
    Case dsUnknown
        sRet = " unknown"
    End Select
    lblStatus.Caption = lblStatus.Caption & sRet
    
    
    Select Case mx.GetPhysicalDiscFormat
    Case pdfCdReadOnly
        sRet = " CD read only"
    Case pdfCdWo
        sRet = " CD recordable"
    Case pdfCdRw
        sRet = " CD rewritable"
    Case pdfUnknown
        sRet = " unknown"
    End Select
    lblFormat.Caption = lblFormat.Caption & sRet
    
    
    Select Case mx.GetDiscType
    Case dtCDDA
        sRet = " digital audio or data"
    Case dtCDI
        sRet = " cd interactive"
    Case dtCDXA
        sRet = " CD XA"
    Case dtUnknown
        sRet = " unknown"
    End Select
    lblType.Caption = lblType.Caption & sRet
    
    sRet = " " & CStr(mx.GetBufferCapacity) & " kb"
    lblBuffer.Caption = lblBuffer.Caption & sRet

    sRet = " " & CStr(mx.GetMaxReadSpeed) & "x"
    lblMaxReadSpeed.Caption = lblMaxReadSpeed.Caption & sRet
    
    sRet = " " & CStr(mx.GetMaxWriteSpeed) & "x"
    lblMaxWrSpeed.Caption = lblMaxWrSpeed.Caption & sRet
    
    sRet = " " & CStr(mx.GetCurrWriteSpeed) & "x"
    lblCurWriteSpeed.Caption = lblCurWriteSpeed.Caption & sRet
    
    
    If mx.IsDriveCapable(BufUndRunFree) = True Then
        sRet = " yes"
    Else
        sRet = " no"
    End If
    lblBUFE.Caption = lblBUFE.Caption & sRet


End Sub

Private Sub EnableControls(bEnable As Boolean)

    cmdRefresh.Enabled = bEnable
    cmdEject.Enabled = bEnable
    cmdErase.Enabled = bEnable
    cmdWrite.Enabled = bEnable
    cmdLock.Enabled = bEnable

End Sub

Private Sub CurrentStatus(bSaveRestore As Boolean)

    Static bOpen As Boolean
    Static bRefresh As Boolean
    Static bLock As Boolean
    Static bEject As Boolean
    Static bWrite As Boolean
    Static bErase As Boolean
    Static bDebug As Boolean
    Static sEvent As String

    If (bSaveRestore = False) Then
        bOpen = cmdOpen.Enabled
        bRefresh = cmdRefresh.Enabled
        bLock = cmdLock.Enabled
        bEject = cmdEject.Enabled
        bWrite = cmdWrite.Enabled
        bErase = cmdErase.Enabled
        bDebug = chkDebug.Enabled
        sEvent = lblEvents.Caption
    Else
        cmdOpen.Enabled = bOpen
        cmdRefresh.Enabled = bRefresh
        cmdLock.Enabled = bLock
        cmdEject.Enabled = bEject
        cmdWrite.Enabled = bWrite
        cmdErase.Enabled = bErase
        chkDebug.Enabled = bDebug
        lblEvents.Caption = sEvent
        bRestore = False
    End If

End Sub

Private Sub mx_EraseComplete()

    lblEvents.Caption = ""
    MsgBox "Disc erasing completed", , App.Title
    EnableControls True
    cmdOpen.Enabled = True
    chkDebug.Enabled = True

End Sub

Private Sub mx_LogicalError(ByVal ErrorId As MoxCdBurnLibCtl.eLogicalErr, ByVal ErrorString As String)
    
    MsgBox "Logical error : " & ErrorString, , App.Title
    If bRestore = True Then Call CurrentStatus(True)

End Sub

Private Sub mx_SysError(ByVal ErrorId As Long, ByVal ErrorString As String)

    MsgBox "System error : " & ErrorString, , App.Title
    If bRestore = True Then Call CurrentStatus(True)
    
End Sub

Private Sub mx_CdrError(ByVal ErrorId As MoxCdBurnLibCtl.eCdrErr, ByVal ErrorString As String)

    MsgBox "Cdr unit error : " & ErrorString, , App.Title
    If bRestore = True Then Call CurrentStatus(True)

End Sub

